package com.blulioncn.matrix.monitoring.controller;

import com.blulioncn.matrix.monitoring.domain.ResultDO;
import com.blulioncn.matrix.monitoring.mapper.one.UserConfigMapper;
import com.blulioncn.matrix.monitoring.pojo.UserConfigModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@RestController
@RequestMapping("/monitoringapi")
public class ApiController extends BaseController{

    @Autowired
    private UserConfigMapper userConfigMapper;

    @PostMapping("/fetchwebsocketurl")
    public ResultDO fetchWebsocketUrl(HttpServletRequest request, HttpServletResponse response
    ) {
        LOG.info("start-----------------------------------fetchwebsocketurl");
        //解决跨域问题
        response.setHeader("Access-Control-Allow-Origin", "*");
        ResultDO resultDO = new ResultDO();
        try {
            UserConfigModel webSocketUrl = userConfigMapper.findByKey("web_socket_url");
            resultDO.success("成功", webSocketUrl.value);
        } catch (Exception e) {
            e.printStackTrace();
        }

        LOG.info("end-----------------------------------fetchwebsocketurl");

        return resultDO;
    }

}
